package com.notecalendar.actions;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.notecalendar.ws.beans.EvernoteUser;





@Controller
public class IndexAction {
	
	private final String VIEW_INDEX = "principal";
	
	@RequestMapping(method=RequestMethod.GET,value="/index")
	public ModelAndView index(){
		
		EvernoteUser user = (EvernoteUser) SecurityContextHolder.getContext().
			getAuthentication().getDetails();
		
		System.out.println("En index.do con auth:"+user.getAuthToken());
		
		/*ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
	    //attr.getRequest().getSession(true).setAttribute("authToken", auth);
	    attr.getRequest().setAttribute("authToken", user.getAuthToken());
	    attr.getRequest().setAttribute("shardId", user.getShardId());
		*/
		return new ModelAndView(VIEW_INDEX, "user", user);
	}

	
}
